package com.alasbusy.alasbusyapp.activity.detail;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import com.alasbusy.alasbusyapp.R;
import com.alasbusy.alasbusyapp.adapter.MusicListAdapter;
import com.alasbusy.alasbusyapp.base.BaseActivity;
import com.alasbusy.alasbusyapp.bean.MusicListBean;
import com.alasbusy.alasbusyapp.utils.CharacterParser;
import com.alasbusy.alasbusyapp.utils.CircleImageView;
import com.alasbusy.alasbusyapp.utils.PinyinComparator;
import com.alasbusy.alasbusyapp.view.SideBar;
import com.zhy.android.percent.support.PercentLinearLayout;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MusicMoreActivity extends BaseActivity {

    private SideBar sideBar;
    private TextView dialog;
    private RecyclerView music_recycle;
    private PinyinComparator pinyinComparator;
    private CharacterParser characterParser;
    private ArrayList<MusicListBean> mAllContactsList;
    private MusicListAdapter adapter;
    String chReg = "[\\u4E00-\\u9FA5]+";// 中文字符串匹配

    private List<MusicListBean> musicList = new ArrayList<>();
    private CircleImageView music_bottom_img;
    private SeekBar music_progress;
    private TextView music_bottom_title;
    private TextView music_bottom_anthor;
    private ImageView music_pre_btn;
    private ImageView music_play_btn;
    private ImageView music_next_btn;

    private boolean isPlay = false;

    @Override
    protected void initView() {
        PercentLinearLayout login_title = findViewById(R.id.music_more_title);
        setTop(login_title);
        getVisibility(true, this);
        getTitle("音乐列表");


        music_recycle = findViewById(R.id.music_recycle);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        music_recycle.setLayoutManager(linearLayoutManager);

        sideBar = (SideBar) findViewById(R.id.sidebar);
        dialog = (TextView) findViewById(R.id.dialog_txt);
        sideBar.setTextView(dialog);
        characterParser = CharacterParser.getInstance();
        adapter = new MusicListAdapter(this);
        music_recycle.setAdapter(adapter);

        music_bottom_img = findViewById(R.id.music_bottom_img);
        music_progress = findViewById(R.id.music_progress);
        music_bottom_title = findViewById(R.id.music_bottom_title);
        music_bottom_anthor = findViewById(R.id.music_bottom_anthor);
        music_pre_btn = findViewById(R.id.music_pre_btn);
        music_play_btn = findViewById(R.id.music_play_btn);
        music_next_btn = findViewById(R.id.music_next_btn);
    }

    @Override
    protected void initData() {
        mAllContactsList = new ArrayList<MusicListBean>();
        setData();

       /* for (int i = 0; i < musicList.size(); i++) {
            mAllContactsList.add(musicList.get(i));
        }*/
        pinyinComparator = new PinyinComparator();
        Collections.sort(mAllContactsList, pinyinComparator);// 根据a-z进行排序源数据
        adapter.changeMoreStatus(MusicListAdapter.LOADING_NO);
        adapter.setList(mAllContactsList);
    }

    @Override
    protected void initListener() {
        // 设置右侧[A-Z]快速导航栏触摸监听
        sideBar.setOnTouchingLetterChangedListener(new SideBar.OnTouchingLetterChangedListener() {

            @Override
            public void onTouchingLetterChanged(String s) {
                // 该字母首次出现的位置
                int position = adapter.getPositionForSection(s);
                if (position != -1) {
                    //mListView.setSelection(position);
                    music_recycle.smoothScrollToPosition(position);
                }
            }
        });
        // item事件
        /*music_recycle.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long arg3) {
                ViewHolder viewHolder = (ViewHolder) view.getTag();
                viewHolder.cbChecked.performClick();
                adapter.toggleChecked(position);
            }
        });*/

        music_play_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(isPlay) {
                    music_play_btn.setImageResource(R.drawable.play_normal);
                }else {
                    music_play_btn.setImageResource(R.drawable.play_press);
                }
                isPlay = !isPlay;
            }
        });
    }

    @Override
    public int getLayout() {
        return R.layout.activity_music_more;
    }


    public void setData() {
        mAllContactsList.clear();
        mAllContactsList.add(new MusicListBean("", "黄色枫叶", "薛子谦"));
        mAllContactsList.add(new MusicListBean("", "认真的雪", "薛子谦"));
        mAllContactsList.add(new MusicListBean("", "刚好遇见你", "李玉刚"));
        mAllContactsList.add(new MusicListBean("", "不可说", "赵丽颖,霍建华"));
        mAllContactsList.add(new MusicListBean("", "回忆那么伤", "孙子涵"));
        mAllContactsList.add(new MusicListBean("", "烹爱", "孙子涵"));
        mAllContactsList.add(new MusicListBean("", "三生三世", "张杰"));
        mAllContactsList.add(new MusicListBean("", "学不会", "林俊杰"));
        mAllContactsList.add(new MusicListBean("", "喜欢寂寞", "苏打绿"));
        mAllContactsList.add(new MusicListBean("", "月光", "胡彦斌"));
        mAllContactsList.add(new MusicListBean("", "诀别诗", "胡彦斌"));
        mAllContactsList.add(new MusicListBean("", "最近的你是我最远的爱", "网络歌手"));
    }


}
